import { Component, Inject, Injectable } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
import { MatDialog, MatDialogRef, MatDialogConfig } from '@angular/material';
import { ConfirmDialogComponent } from '../component/confirm/confirm.dialog.component';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class ConfirmDialogService {

    constructor( @Inject(MatDialog) public confirmDialog: MatDialog) {
    }

    public confirm(contentOrConfig: any, title?: string): Observable<any> {
        // 设置dialog的属性，宽度，高度，内容等
        let config = new MatDialogConfig();
        config = { width: '300px', height: '200px' };
        if (contentOrConfig instanceof Object) {
            config.data = contentOrConfig;
        } else if ((typeof contentOrConfig) === 'string') {
            config.data = {
                content: contentOrConfig,
                title: title
            };
        }
        return this.confirmDialog.open(ConfirmDialogComponent, config).afterClosed();
    }

}
